package com.cskaoyan.market.admin.service.impl;

import java.time.LocalDateTime;
import java.util.List;

import org.apache.ibatis.session.SqlSession;

import com.cskaoyan.market.admin.service.AdminCouponService;
import com.cskaoyan.market.db.domain.MarketCoupon;
import com.cskaoyan.market.db.domain.MarketCouponExample;
import com.cskaoyan.market.db.mapper.MarketCouponMapper;
import com.cskaoyan.market.util.MyBatisUtil;

/**
 * @author BlackFlame33
 * @date 2023/03/21
 **/
public class AdminCouponServiceImpl implements AdminCouponService {
    @Override
    public List<MarketCoupon> getCouponList(int page, int limit, String sort, String order) {
        SqlSession session = MyBatisUtil.getSession();
        MarketCouponMapper mapper = session.getMapper(MarketCouponMapper.class);
        List<MarketCoupon> marketCoupons = mapper.selectByExample(new MarketCouponExample());
        session.commit();
        session.close();
        return marketCoupons;
    }

    @Override
    public int createCoupon(MarketCoupon data) {
        SqlSession session = MyBatisUtil.getSession();
        MarketCouponMapper mapper = session.getMapper(MarketCouponMapper.class);
        data.setAddTime(LocalDateTime.now());
        data.setUpdateTime(LocalDateTime.now());
        data.setDeleted(false);
        int code = mapper.insert(data);
        session.commit();
        session.close();
        return code;
    }
}